<?php

namespace Ticket\Repository;

use Doctrine\ORM\EntityRepository;

class TicketRepository extends EntityRepository {

    public function findByClient($client) {
        $qb = $this->createQueryBuilder('t');
        $qb->where('t.client = :clientId');
        $qb->orderBy('t.time', 'DESC');

        $qb->setParameter('clientId', $client->getId());
        return $qb->getQuery()->getResult();
    }

    public function findOpenedByUser($user) {
        $qb = $this->createQueryBuilder('t');
        $qb->where('t.user = :userId and t.closed=false');
        $qb->orderBy('t.time', 'DESC');

        $qb->setParameter('userId', $user->getId());
        return $qb->getQuery()->getResult();
    }

}